package com.tjec.framework.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.tjec.common.utils.StringUtils;
import com.tjec.project.businessWorkbench.dto.BmsPickupTimerDto;
import com.tjec.project.businessWorkbench.service.IBmsBusinessPickupService;
import com.tjec.project.msg.service.MsgService;

/**
 * 收资管理提醒
 * @author pangyongfeng
 *
 */

@Component
@PropertySource("classpath:/quartz.properties")
public class PickupSchedule {
	
	@Resource
	private IBmsBusinessPickupService businessPickupService;
	
	@Resource
	private MsgService msgService;
	
	 /**
     * 每天早上8点半执行
     */
//	 生产服务器EC1定时任务:
//	 @Scheduled(cron="0 40 8 * * ?")
//	 生产服务器EC2定时任务:
//	 @Scheduled(cron="0 30 8 * * ?")
    @Scheduled(cron="${businessWorkbench.pickup.timer}")
    public void cronJob(){
    	List<BmsPickupTimerDto> res = businessPickupService.getSendMsgInfo();
    	if(res!=null && res.size()>0) {
    		res.forEach(item->{
    			if(item.getCounts()<1) {
    				if(StringUtils.isNotBlank(item.getManagerPhone())) {
        				msgService.SendMsg2(item.getManagerPhone(), item.getLeaderName()+"：“【"+item.getProjectName()+"】项目下的【"+item.getBusinessName()+"】业务的收资文件《"+item.getPickupName()+"》3天后将到最迟收资日期，请尽快完成”");
        			}else {
        				msgService.SendMsg2(item.getLeaderPhone(), item.getLeaderName()+"：“【"+item.getProjectName()+"】项目下的【"+item.getBusinessName()+"】业务的收资文件《"+item.getPickupName()+"》3天后将到最迟收资日期，请尽快完成”");
        			}
    				item.setCounts(item.getCounts()+1);
    				businessPickupService.updatePickupCounts(item);
    			}
    		});
    	}
    	
    	
    }

}
